

//
//  RedPacketCell.m
//  LuxuryGoods
//
//  Created by DCQ on 2018/5/24.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "RedPacketCell.h"
#import "RedPacketListModel.h"

@interface RedPacketCell()
@property (weak, nonatomic) IBOutlet UILabel *redPacketTitle;
@property (weak, nonatomic) IBOutlet UILabel *redPacketDetail;
@property (weak, nonatomic) IBOutlet UILabel *redPTimer;
@property (weak, nonatomic) IBOutlet UIImageView *stateImgV;
@property (weak, nonatomic) IBOutlet UILabel *parValue;
@property (weak, nonatomic) IBOutlet UIImageView *iconImgV;

@end
@implementation RedPacketCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setupData:(id)data  withStyle:(RedPacketCellStyle)style{
    
    RedPacketModel * model = data;
    BOOL stateImgVHidden = NO;
    BOOL userBtnHideen = NO;
    NSString * stateImgName = @"";
    NSString * iconImgName = @"";
    UIColor *parValueColor = UIColorFromRGB(0xCDCDCD);
    if (style == RedPacketCellStyle_overdue) {
        userBtnHideen = YES;
        stateImgVHidden = NO;
        stateImgName = @"youhuiquan_guoqi";
        iconImgName = @"hongbao_hui";
    }else if (style == RedPacketCellStyle_used){
        userBtnHideen = YES;
        stateImgName = @"hongbao_shiyong";
         iconImgName = @"hongbao_hui";
    }else if (style == RedPacketCellStyle_noUsed){
        userBtnHideen = NO;
        stateImgName = @"";
        iconImgName = @"hongbao_hongbao";
         parValueColor = UIColorFromRGB(0xFF7E57);
    }
    self.parValue.text = [NSString stringWithFormat:@"%@元",model.par_value];
    self.stateImgV.image = [UIImage imageNamed:stateImgName];
    self.stateImgV.hidden = stateImgVHidden;
    self.redPTimer.text = [NSString stringWithFormat:@"过期时间:%@",[self timeFormat:model.expirytime]];
    self.parValue.textColor = parValueColor;
    self.redPacketTitle.text = model.redpack_name;
    self.redPacketDetail.text = model.resources;
}

- (NSString *)timeFormat:(NSString *)timeStr{
     NSString * tempStr = timeStr;
    if (timeStr ) {
        if (timeStr.length >= 10) {
            tempStr = [timeStr substringToIndex:10];
        }
    }else{
        tempStr = @"";
    }
    
    return tempStr;
    
}
@end
